<?php
  class Plugins_Discount extends model {
  
  
  
  function getformadd($productid="")
  {
  
  
  
  
  $echo=1;
//  $str='<div class="classmap"> 
//   <div class="mapdata" style="width:640px;height:360px">textmap</div>
//   <div><input type="text" name="detail[]"><input type="hidden" name="lat[]"><input type="hidden" name="lng[]"></div>
//  </div>
//  ';
$code  = '<div class="wrpPlg clBg5 clBd2 bdFull">'."\n";
$code .= '<div class="wrpOutAtcPlg">'."\n";
$code .= '<div class="wrpAtcPlg">'."\n";
$code .= '<span class="ico icoOri icoDiscountPlg"></span>'."\n";
$code .= '<div class="spnAtcPlg clTxtW">'."\n";
$code .= '<span class="txtAtcPlg fs03">Discount</span>'."\n";
$code .= '</div>'."\n";
$code .= '</div>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="wrpTl">'."\n";
$code .= '<div title="Close" class="btnIco closeTl clBd3 mgBtm10 deleterowbutton">'."\n";
$code .= '<span class="ico icoCloseTl"></span>'."\n";
$code .= '</div>'."\n";
$code .= '</div>'."\n";
$code .= '<form class="frmFrmPlg clTxt3 fs03">'."\n";
$code .= '<fieldset class="wrpFrmPlg">'."\n";
$code .= '<table class="tbGenInfo tbAddCtnt clTxt3 fs03">'."\n";
$code .= '<tbody><tr>'."\n";
$code .= '<th>Discount Name</th>'."\n";
$code .= '<td>'."\n";
$code .= '<input type="text" name="discountname[]" class="clBg5 clBd2 fs03 clTxt2">'."\n";
$code .= '</td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<th>Value Discount (Baht)</th>'."\n";
$code .= '<td>'."\n";
$code .= '<input type="text" name="discountprice[]" class="clBg5 clBd2 fs03 clTxt2">'."\n";
$code .= '</td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<th>Coupon Code</th>'."\n";
$code .= '<td>'."\n";
$code .= '<input type="text" name="discountcode[]" class="inpCoup clBg5 clBd2 fs03 clTxt2">'."\n";
$code .= '<input type="button" name="discountgenerate[]" value="Generate" class="btnGen btnGenCoup clTxtW cutTxt clBgBt1 fs04">'."\n";
$code .= '</td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<th>Period</th>'."\n";
$code .= '<td>'."\n";
$code .= '<input type="text" placeholder="Start Date" name="discountstartdate[]" class="inpDiscount w120 clBg5 clBd2 fs03 clTxt2">'."\n";
$code .= '<span>to</span>'."\n";
$code .= '<input type="text" placeholder="End Date"  name="discountenddate[]" class="inpDiscount w120 clBg5 clBd2 fs03 clTxt2">'."\n";
$code .= '</td>'."\n";
$code .= '</tr>'."\n";
$code .= '</tbody></table>'."\n";
$code .= '</fieldset>'."\n";
$code .= '</form>'."\n";
$code .= '</div>';
  
  
  
  $arraydata['form']=addslashes(str_replace(array("\r", "", "\r"), '', $code));
//  $arraydata['js'][]=pluginjsinfo.'/map.js';
//  $arraydata['js'][]='https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true';
 // $arraydata['js'][]=baseinfo.'/js/gmap3.js';
  //$arraydata['js'][]=baseinfo.'/js/jquery.Jcrop.min.js';
 // $arraydata['js'][]=baseinfo.'/js/jquery.iuploader-1.0.js';
  
  
      
  
  
  
  return $arraydata;
  
  
  
  
  
  
  
  }
  
  function getformlanding($arraydata)
  {
  
$code  = '<div class="ldIt wrpFrmLd clBg4">'."\n";
$code .= '<div class="wrpHdInfoGen mgBtm10">'."\n";
$code .= '<h2 class="clTxt2 fs04">Discount</h2>'."\n";
$code .= '</div>'."\n";
$code .= '<table class="tbGenInfo tbFrmLd clTxt3 fs03">'."\n";
$code .= '<tbody><tr>'."\n";
$code .= '<th>Discount Name</th>'."\n";
$code .= '<td>'.$arraydata['name'].'</td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<th>Value Discount</th>'."\n";
$code .= '<td>'.$arraydata['price'].' Baht</td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<th>Coupon Code</th>'."\n";
$code .= '<td>'.$arraydata['code'].'</td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<th>Period</th>'."\n";
$code .= '<td>'.$arraydata['startnewdate'].' - '.$arraydata['endnewdate'].'</td>'."\n";
$code .= '</tr>'."\n";
$code .= '</tbody></table>'."\n";
$code .= '</div>';
  $data['str']=$code;
$data['target']='secondtarget';
  
  return $data; 

  
  }
  
  function codenewcheck()
  {
   $code=createRandomPassword();
   $sql="select * from tb_plugins_discount where tb_plugins_discount.code='".$code."'";
    $arraydiscount=$this->db->db_set_1recordrow($sql);
    
    if($arraydiscount['discountid'])
    {
     return $this->codenewcheck();
    
    }else
    {
    
    return $code;
    
    
    
    }
  
  
  }
  
  function generatediscount()
  {
  
    
    
    $code=$this->codenewcheck();
    
    
    
    $arraydata['data']=$code;
    
    
    return $arraydata;
    
    
      
   
    
  
  
  }
  
  function getplugin($plugreid)
  {
  
     $sql="select *,DATE_FORMAT(tb_plugins_discount.startdate,'%d/%m/%Y') startnewdate,DATE_FORMAT(tb_plugins_discount.enddate,'%d/%m/%Y') endnewdate from tb_plugins_discount where plugreid=".$plugreid;
     $arrayplugin=$this->db->db_set_1recordrow($sql);
     
   
     
     
  
     return $arrayplugin;

  
  
  

  
  }
  
  function saveplugin($arraydata,$productid,$plugreid)
  {
  
  $arraydata['productid']=$productid;
  $arraydata['plugreid']=$plugreid;
  
  
  
     $sql="select * from tb_plugins_discount where tb_plugins_discount.code='".$arraydata['code']."'";
    $arraydiscount=$this->db->db_set_1recordrow($sql);
    
    if($arraydiscount['discountid'])
    {
     $arraydata['code']= $this->codenewcheck();
    
    }
    
    
     if($arraydata['startdate'])
  {
  list($day,$month,$year)=explode("/",$arraydata['startdate']);
  
  $arraydata['startdate']=$year.'-'.$month.'-'.$day;
  
  }
  
  
    if($arraydata['enddate'])
  {
  list($day,$month,$year)=explode("/",$arraydata['enddate']);
  
  $arraydata['enddate']=$year.'-'.$month.'-'.$day;
  
  }
  
  
  
  $this->db->db_set($arraydata,'tb_plugins_discount');
  
  }
  
  
  }
?>
